package com.example.music.config;

import com.example.music.utils.Constant;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * ClassName: LoginInterceptor
 * Package: com.example.music.config
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-05-31
 * Time: 16:02
 */

public class LoginInterceptor implements HandlerInterceptor {
    //创建登录拦截器 实现HandlerInterceptor 重写preHandle方法
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //首先判断Session
        HttpSession httpSession = request.getSession();
        if (httpSession == null || httpSession.getAttribute(Constant.USERINFO_SESSION_KET) == null){
            //没有登录
            return false;
        }
        //成功登录
        return true;
    }
}
